package com.t01.bdqn.servlet;


import com.t01.bdqn.entity.Supplier;
import com.t01.bdqn.entity.dto.LayuiPage;
import com.t01.bdqn.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("supplierMvc")
public class SupplierMvc {
    @Autowired
    SupplierService supplierService;

    @RequestMapping(value = "getListSupplier")
    @ResponseBody
    @CrossOrigin
    public LayuiPage<Supplier> getListSupplier(Integer page, Integer limit, Integer id, String name) {
        LayuiPage<Supplier> layuiPage = new LayuiPage<>();
        layuiPage.setCode(0);
        layuiPage.setMsg("查询成功");
        layuiPage.setData(supplierService.getListSupplierInfo(page, limit, id, name));
        layuiPage.setCount(supplierService.count(id, name));
        return layuiPage;
    }

    @RequestMapping(value = "addData")
    @ResponseBody
    @CrossOrigin
    public boolean addData(Integer id, String name,Integer suid){
        if (null != suid){
            Supplier supplier = new Supplier();
            supplier.setSupplierId(id);
            supplier.setSupplierName(name);
            supplier.setId(suid);
            supplierService.updateData(supplier);
        }else {
            supplierService.addData(id,name);
        }

        return true;
    }
    @RequestMapping(value = "Sudelete")
    @ResponseBody
    @CrossOrigin
    public int deleteInfo(Integer id){
        return supplierService.deleteSupplier(id);
    }
}
